//
//  SettingSafeCodeViewController.m
//  JiuJiuShangCheng
//
//  Created by jiujiukeji on 2018/8/21.
//  Copyright © 2018年 jiujiukeji. All rights reserved.
//

#import "SettingSafeCodeViewController.h"
#import "ChangePWItem.h"

@interface SettingSafeCodeViewController ()
@property (nonatomic, strong) ChangePWItem *item1;
@property (nonatomic, strong) ChangePWItem *item2;

@end

@implementation SettingSafeCodeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = UIColorFromRGB(0xf5f5f5);
    [self loadBaseTitleLable:@"设置安全密码"];
    
    [self setUpUI];
}
- (void)setUpUI
{
    ChangePWItem *item1 = [[ChangePWItem alloc] init];
    item1.textField.placeholder = @"请输入新密码";
    item1.textField.secureTextEntry = YES;
    [self.view addSubview:item1];
    [item1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(rateWidth(660), rateHeight(90)));
        make.top.equalTo(self.view).offset(rateHeight(30)+SafeAreaTopHeight);
        make.centerX.equalTo(self.view);
    }];
    self.item1 = item1;
    
    ChangePWItem *item2 = [[ChangePWItem alloc] init];
    item2.textField.placeholder = @"请再次输入新密码";
    item2.textField.secureTextEntry = YES;
    [self.view addSubview:item2];
    [item2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(rateWidth(660), rateHeight(90)));
        make.top.equalTo(item1.mas_bottom).offset(rateHeight(30));
        make.centerX.equalTo(self.view);
    }];
    self.item2 = item2;
    
    UIButton *btn = [UIButton buttonWithTitle:@"提交" fontSize:16 titleColor:UIColorWhite background:navBarColor cornerRadius:3];
    [self.view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(item2.mas_bottom).offset(rateHeight(40));
        make.centerX.equalTo(self.view);
        make.size.mas_offset(CGSizeMake(rateWidth(660), rateHeight(90)));
    }];
    [btn addTarget:self action:@selector(settingSafeCode) forControlEvents:(UIControlEventTouchUpInside)];
}
- (void)settingSafeCode
{
    NSString *code = [NSString stringWithFormat:@"%@%@",safeCode,[GetTimestamp getNowTimeTimestamp]];
    [MBProgressHUD showMessage:nil toView:self.view];
    [TFNetworking postWithURLString:[NSString stringWithFormat:@"%@/api/json/member/safe.ashx?action=paymentpass&companyid=%@&code=%@&timestamp=%@",kServerURL,companyId,[MD5Encrypt  MD5ForLower32Bate:code],[GetTimestamp getNowTimeTimestamp]] parameters:@{@"oldpass":@"",@"newpass":self.item1.textField.text,@"confirmpass":self.item2.textField.text} success:^(id responseObject) {
        [MBProgressHUD hideHUDForView:self.view];
        if (responseObject) {
            if ([responseObject[@"status"] intValue] == 1) {
                [self.navigationController popViewControllerAnimated:YES];
                [MBProgressHUD showSuccess:responseObject[@"returnMsg"]];
            } else {
                [TFHUD addRemindHUD:self.view message:responseObject[@"returnMsg"]];
            }
        }
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        [TFHUD addRemindHUD:self.view message:@"网络不给力..."];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
